package com.lzlclass.util;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * 扩展国际化消息
 * */

public class MylocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
//        获取请求中的语言参数
        String yuyan = request.getParameter("l");
        System.out.println(yuyan);
        Locale locale = Locale.getDefault();;//如果没有就是用默认的
        if(!StringUtils.isEmpty(yuyan)){
//            zh_CN 国家_地区
            String[] split = yuyan.split("_");
            locale=new Locale(split[0],split[1]);
        }

        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}